package com.yjhb.android.sbz.adapter;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.yjhb.android.sbz.R;
import com.yjhb.android.sbz.entity.TaskStep;
import com.jojo.android.zxlib.base.BaseRecyclerAdapter;

/**
 * 创建者 zx
 * 创建时间 2020/11/25 11:45
 */
public class StepSettingAdapter extends BaseRecyclerAdapter<StepSettingAdapter.StepHolder, TaskStep> {
    private final String TAG = "StepSettingAdapter";
    private OnItemClickListener onItemClickListener;

    public StepSettingAdapter(Context context) {
        super(context);
    }


    @Override
    public void onBindViewHolder(@NonNull StepHolder stepHolder, int i) {
        try {
            final TaskStep step = data.get(i);
            stepHolder.text_tv.setText(data.get(i).getTitle());
            stepHolder.num_tv.setText("" + (i + 1));
            stepHolder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (onItemClickListener != null) {
                        onItemClickListener.onItemClick(step);
                    }
                }
            });
        } catch (Exception e) {
        }
    }


    @Override
    protected StepHolder getHolder(View v) {
        return new StepHolder(v);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.item_step;
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener {
        void onItemClick(TaskStep step);
    }


    class StepHolder extends RecyclerView.ViewHolder {
        TextView text_tv;
        TextView num_tv;

        public StepHolder(@NonNull View itemView) {
            super(itemView);
            text_tv = itemView.findViewById(R.id.text_tv);
            num_tv = itemView.findViewById(R.id.num_tv);
        }
    }

}
